<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>GitHub Issue 1452</title>
    <link rel="stylesheet" id="theme-link" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
    <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
    <script src="../../../dist/jsoneditor.js"></script>
  </head>
  <body>
    <div class="container">
      <h1>Test</h1>
      <a href="https://github.com/json-editor/json-editor/issues/1452">Link to issue</a>
      <div id='editor_holder'></div>
      <button id="set-value">Set Value</button>
    </div>

    <script>
      const value = document.querySelector('#value')
      const defaultSchema = {
        "title": "Dependencies",
        "type": "object",
        "properties": {
          "category": {
            "title": "Category",
            "type": "string",
            "enum": [
              "Chocolates",
              "Vegetables",
              "Icecreams"
            ]
          },
          "subcategory1": {
            "title": "Subcategory",
            "type": "string",
            "enum": [
              "Dark chocolate",
              "Milk chocolate",
              "White chocolate",
              "Gianduja chocolate"
            ],
            "options": {
              "dependencies": {
                "category": "Chocolates"
              }
            }
          },
          "subcategory2": {
            "title": "Subcategory",
            "type": "string",
            "enum": [
              "Broccoli",
              "Cabbage",
              "Carrot",
              "Tomato"
            ],
            "options": {
              "dependencies": {
                "category": "Vegetables"
              }
            }
          },
          "subcategory3": {
            "title": "Subcategory",
            "type": "string",
            "enum": [
              "Frozen yogurt",
              "Booza",
              "Ice milk"
            ],
            "options": {
              "dependencies": {
                "category": "Icecreams"
              }
            }
          }
        }
      }

      const editor = new JSONEditor(document.getElementById('editor_holder'), {
        iconlib: 'fontawesome5',
        schema: defaultSchema,
        theme: 'bootstrap3'
      })

      const setValue = document.querySelector('#set-value')

      setValue.addEventListener('click', () => {
        editor.setValue({
          "category": "Chocolates",
          "subcategory1": "Dark chocolate"
        })
      })
    </script>
  </body>
</html>
